Android使用ConstraintLayout布局设置TextView基线对齐 |
您所在的位置:网站首页 › constraintlayout 基线对齐 › Android使用ConstraintLayout布局设置TextView基线对齐 |
前几天做Android的时候碰到以前的开发人员挖的坑 这个约束布局网上说是为了提高绘制页面效率而开发的新式布局 具体大家去百度吧,看看怎么解决咱们这个TextView的基线(H5中有基线,我就暂时这么叫吧)问题! 然后一分钟来了解一下这个布局怎么放标签: … Button1 :app:layout_constraintBottom_toTopOf="@id/iv_head" 我们把这个属性拆开来看, constraintBottom 指的本身的底部,即 Button1 的顶部, toTopOf 是指 ImageView 的顶部,那么这句话的意思就是 Aligns the bottom of the desired view to the top of another.(官方原文) 翻译一下就是 Button1 的底部要和 ImageView 的顶部对齐 Button1 app:layout_constraintRight_toLeftOf="@id/iv_head" 根据上面的规则我们就知道 Button1 的右边要和 ImageView 的左边对齐。 其实很简单就是说两个 View 的某个方位要对齐 没了,就这么简单,其它属性可以举一反三,它比 RelativeLayout 控制起来更加得以就手。 layout_constraintTop_toTopOf — Align the top of the desired view to the top of another. layout_constraintTop_toBottomOf — Align the top of the desired view to the bottom of another. layout_constraintBottom_toTopOf — Align the bottom of the desired view to the top of another. layout_constraintBottom_toBottomOf — Align the bottom of the desired view to the bottom of another. layout_constraintLeft_toTopOf — Align the left of the desired view to the top of another. layout_constraintLeft_toBottomOf — Align the left of the desired view to the bottom of another. layout_constraintLeft_toLeftOf — Align the left of the desired view to the left of another. layout_constraintLeft_toRightOf — Align the left of the desired view to the right of another. layout_constraintRight_toTopOf — Align the right of the desired view to the top of another. layout_constraintRight_toBottomOf — Align the right of the desired view to the bottom of another. layout_constraintRight_toLeftOf — Align the right of the desired view to the left of another. layout_constraintRight_toRightOf — Align the right of the desired view to the right of another. If desired, attributes supporting start and end are also available in place of left and right alignment. 到此,你已经掌握了一大半的 ConstraintLayout 知识点 … 好了,上面这段不是我总结的,刚开始在网上搜,结果各种文字加图的PPT解释的人一头雾水,这篇讲得真的很好,链接页: https://www.cnblogs.com/qqhfeng/p/7366560.html 代码: 没有多层的嵌套,感觉这才是约束布局的强大之处,控件顺序无所谓,只要调好参考物的位置就行了,看网上测试据说性能可以提升46%,提升一半啊! ok,写BUG去了! 2019.4.23补充, 目前经历来看,用此布局设计控件比较多的比较复杂的页面,需要提前构思好各个控件之间的关联关系,因为后期如果在中间新加控件的话,势必会影响到之前的控件关联关系,这一点个人感觉也算是约束布局的一个缺点吧,牵一发而动全身! |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |